//
//  DPWalletWithDrawInputCell.swift
//  DoctorEPlus
//
//  Created by 王林波 on 2021/3/8.
//

import UIKit

class DPWalletWithDrawInputCell: UITableViewCell {
    
    var didChoseTypeBlock:((Int) -> Void)?
    
    var didMoneyInputBlock:((String) -> Void)?
    
    
    @IBOutlet weak var inputMoneyTextFiled: UITextField!
    
    @IBOutlet weak var lastAmount_label: UILabel!
    
    var maxValue: String = "0" {
        didSet {
            self.lastAmount_label.text = maxValue
        }
    }
    
    
    @IBAction func allWithDrawAct(_ sender: UIButton) {
        self.didChoseTypeBlock?(0)
    }
    
    @IBAction func resetWithDrawAct(_ sender: UIButton) {
        self.inputMoneyTextFiled.text = ""
        self.didChoseTypeBlock?(1)
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.inputMoneyTextFiled.delegate = self
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    
    static var cellHeight: CGFloat {
        get {
            return 180
        }
    }
}

extension DPWalletWithDrawInputCell: UITextFieldDelegate {
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let result = DPAlipayManager.judgeTextAvaliable(textField.text ?? "", string, self.maxValue)
        textField.text = result
        return false
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        self.didMoneyInputBlock?(textField.text ?? "")
    }
}
